package com.eqxiu.ieditor.manager.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eqxiu.ieditor.api.order.IOrderServiceApi;
import com.eqxiu.ieditor.manager.utils.UserContext;
import eqxiu.passport.sdk.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eqxiu.ieditor.manager.utils.RequestUtils;

@Controller
@RequestMapping("/m/ie/order")
public class OrderController {
	@Autowired
	private IOrderServiceApi orderServiceApi;

	@PostMapping("/{page}")
	public String index(@PathVariable String page) {
		return "order/" + page;
	}

	/**
	 * @description 根据条件分页查找订单
	 * @author ranger
	 * @date 2017年5月5日
	 */
	@PostMapping("/list")
	@ResponseBody
	public Map<String, Object> findOrderList(HttpServletRequest request, HttpServletResponse response) {
		// 按条件过滤
		Map<String, String> params = setParam(request);
		return orderServiceApi.findByParams(params);
	}
	
	/**
	 * @description 根据条件分页查找订单总数,支付总数
	 * @author ranger
	 * @date 2017年5月5日
	 */
	@PostMapping("/numbers")
	@ResponseBody
	public Map<String, Object> findOrderNumber(HttpServletRequest request, HttpServletResponse response) {
		// 按条件过滤
		Map<String, String> params = setParam(request);
		return orderServiceApi.findNumberByParams(params);
	}

	private Map<String, String> setParam(HttpServletRequest request) {
		Map<String, String> params = RequestUtils.getRequestParamMap(request);
		UserContext.getUser();
		UserDTO user = UserContext.getUser();
		params.put("userId", user.getId());
		return params;
	}

}
